package com.example.demo;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentController {
	
	@Autowired
	private StudentRepository repo;
	
	@PostMapping("add")
	public Student add(@RequestParam("name") String name,@RequestParam("age") Integer age) {
		Student s  = new Student();
		s.setAge(age);
		s.setName(name);
		return repo.save(s);
	}

	@GetMapping("getInparam")
	public Student getInparam(@RequestParam("id") Integer id) {
		
		return repo.findOne(id);
	}
	
	
	@GetMapping("get/{id}")
	public Student get(@PathVariable("id") Integer id) {
		
		return repo.findOne(id);
	}
	
	@DeleteMapping("del/{id}")
	public void del(@PathVariable("id") Integer id) {
		 repo.delete(id);
	}
	
}
